package com.shareyi.study.springboot.configuaration;

import org.springframework.boot.autoconfigure.velocity.VelocityProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;

/**
 * @autor: zhangshibin
 * @description velocity 配置文件
 * @since 2018/6/21
 */
@Configuration
public class VelocityConfiguration extends WebMvcConfigurerAdapter {


    @Bean(name="velocityViewResolver")
// 现在这个class不再是layout的，所以要把对应的 ViewResolver改成对应的，由于没有
// toolboxviewresolver，就用父类 veclotiyviewresoler
    public VelocityViewResolver velocityViewResolver(VelocityProperties properties) {
        VelocityLayoutViewResolver viewResolver = new VelocityLayoutViewResolver();
        viewResolver.setViewClass(VelocityLayoutToolboxView.class);
        properties.applyToViewResolver(viewResolver);// 设置默认属性，比如前缀和后缀
        viewResolver.setLayoutUrl("layout/default.vm");
        return viewResolver;
    }

}
